home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 12 / Amiga Format AFCD12 (Apr 1997, Issue 96).iso / -readerstuff- / manolis_pappas / mathfx / examples / 3d.c next >
Encoding:
C/C++ Source or Header  |  1997-01-29  |  1.5 KB  |  65 lines

  1. /* Demonstration of 3-D plotting with MathFX library. */
  2. /* Copyright (©) 1995, The Xperts Group Inc. All Rights Reserved. */
  3. /* Author: Manolis S Pappas. */
  4.  
  5. #include <math.h>
  6.       
  7. #define   NPTS   41
  8.  
  9. static int opt[] = {1,   2,   3,   3};
  10.  
  11. static float alt[] = {60.0,20.0,60.0,60.0};
  12.  
  13. static float az[] = {30.0,60.0,120.0,160.0};
  14.  
  15. static char *title[4] =  {
  16.    "\\fr3-D Plot 1 - Alt=60, Az=30, Opt=1",
  17.    "\\fr3-D Plot 2 - Alt=20, Az=60, Opt=2",
  18.    "\\fr3-D Plot 3 - Alt=60, Az=120, Opt=3",
  19.    "\\fr3-D Plot 4 - Alt=60, Az=160, Opt=3"
  20. };
  21.  
  22. main()
  23. {
  24.    int i, j, k;
  25.  
  26.    float x[NPTS], y[NPTS], z[NPTS][NPTS];
  27.    float xx, yy, r;
  28.    int work[4*NPTS];
  29.  
  30.    for (i=0; i<NPTS; i++)  {
  31.       x[i] = (i-(NPTS/2))/(double)(NPTS/2);
  32.       y[i] = (i-(NPTS/2))/(double)(NPTS/2);
  33.    }
  34.  
  35.    for (i=0; i<NPTS; i++)  {
  36.       xx = x[i];
  37.       for (j=0; j<NPTS; j++)  {
  38.          yy = y[j];
  39.          r = sqrt(xx*xx + yy*yy);
  40.          z[i][j] = exp(-r*r) * cos(2.0*3.141592654*r);
  41.       }
  42.    }
  43.  
  44.    fxstar(1,1);
  45.  
  46.    for (k=0; k<4; k++)  {
  47.       fxadv(0);
  48.       fxvpor(0.0,1.0,0.0,0.9);
  49.       fxwind(-1.0,1.0,-0.9,1.1);
  50.  
  51.       fxw3d(1.0,1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,alt[k],az[k]);
  52.       fxbox3("bnstu","x axis",0.0,0,"bnstu","y axis",0.0,0,
  53.              "bcmnstuv","z axis",0.0,0);
  54.       plot3d(x,y,z,work,NPTS,NPTS,NPTS,opt[k]);
  55.       if(k==1 || k==3)
  56.          fxside3(x,y,z,NPTS,NPTS,NPTS,opt[k]);
  57.       if(k==2 || k==3)
  58.          fxgrid3(0.0);
  59.       fxmtex("t",1.0,0.5,0.5,title[k]);
  60.    }
  61.  
  62.    fxtext();
  63.    fxend();
  64. }
  65.